package cn.ljy.mes.model;

import cn.ljy.authority.model.SysFileResource;
import cn.ljy.authority.model.SysUser;
import cn.ljy.common.model.BaseModel;
import cn.ljy.common.model.validate.AddWorkValidation;
import cn.ljy.common.model.validate.UpdateWorkValidation;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.*;
import java.math.BigDecimal;
import java.util.List;

@ApiModel(value = "商城汽车商品")
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false, of = {"id"})
public class ShopCarProduct extends BaseModel {

    @ApiModelProperty(value = "商品ID", example = "28b4d848-7b7f-11f0-a22e-0250f2000002")
    @NotNull(groups = UpdateWorkValidation.class, message = "商品ID不能为空")
    private String id;

    @ApiModelProperty(value = "汽车配置", required = true)
    @NotNull(groups = AddWorkValidation.class, message = "汽车配置不能为空")
    private MesCarModelConfig carModelConfig;

    @ApiModelProperty(value = "商品名称", required = true, example = "宏光MINIEV 2025款 四门版 进阶款")
    @NotBlank(groups = AddWorkValidation.class, message = "商品名称不能为空")
    @Length(min = 1, max = 50, message = "商品名称长度必须在 {min} - {max} 之间")
    private String name;

    @ApiModelProperty(value = "商品简介", example = "2025款进阶版，续航里程提升")
    private String description;

    @ApiModelProperty(value = "产品详细描述", example = "采用最新电池技术，续航里程达300公里...")
    private String content;

    @ApiModelProperty(value = "原价", required = true, example = "44800.00")
    @NotNull(groups = AddWorkValidation.class, message = "指导价不能为空")
    @DecimalMin(value = "0.00", inclusive = false,  message = "原价必须大于0")
    @Digits(integer = 10, fraction = 2, message = "原价最多10位整数、2位小数")
    //后放弃必须包含两位小数，因为对前端要求较麻烦，或者说是需要在后端做转换，故暂时放弃
//    @DecimalMax10Int2Scale(message = "原价最多10位整数且必须包含2位小数")
    private BigDecimal originalPrice;

    @ApiModelProperty(value = "促销价格", required = true, example = "42800.00")
    @NotNull(groups = AddWorkValidation.class, message = "促销价格不能为空")
    @DecimalMin(value = "0.00", inclusive = false, message = "促销价格必须大于0")
    @Digits(integer = 10, fraction = 2, message = "促销价格最多10位整数、2位小数")
    //后放弃必须包含两位小数，因为对前端要求较麻烦，或者说是需要在后端做转换，故暂时放弃
//    @DecimalMax10Int2Scale(message = "原价最多10位整数且必须包含2位小数")
    private BigDecimal price;

    @ApiModelProperty(value = "库存数量", example = "100")
    @NotNull(groups = AddWorkValidation.class,message = "库存不能为空")
    @Min(value = 0, message = "库存数量不能小于0")
    private Integer repository;

    @ApiModelProperty(value = "封面图片URL", example = "https://example.com/miniev-cover.jpg")
    @NotNull(groups = AddWorkValidation.class,message="封面图片不能为空")
    private SysFileResource coverImage;//标题图片

    @ApiModelProperty(value = "商品图集", notes = "JSON数组格式的图片URL列表")
    private List<String> gallery;

    @ApiModelProperty(value = "是否上架", required = true, example = "true")
    @NotNull(groups = AddWorkValidation.class, message = "上架状态不能为空")
    private Boolean onSale;

    @ApiModelProperty(value = "排序权重", example = "100")
    @NotNull(groups = AddWorkValidation.class, message = "排序权重不能为空")
    @Min(value = 0, message = "排序权重不能小于0")
    private Integer orderNum;

    @ApiModelProperty(value = "创建管理员")
    private SysUser creator;

    @ApiModelProperty(value = "最后编辑管理员")
    private SysUser editor;

    // 非数据库字段
//    @ApiModelProperty(value = "品牌名称", example = "五菱宏光")
//    private String brandName;
//
//    @ApiModelProperty(value = "车型名称", example = "MINIEV")
//    private String modelName;
//
//    @ApiModelProperty(value = "月销量", example = "120")
//    private Integer monthlySales;


    public ShopCarProduct(String id) {
        this.id = id;
    }
}
